//
// Created by guanyicheng on 2022/3/8.
//
#include "../../common.h"

class Solution {
public:
    int totalFruit(vector<int> &fruits) {
        int left = 0, right = 0, typeNum = 0, maxLength = -1;
        unordered_map<int, int> types{};
        for (; right < fruits.size(); right++) {
            if (types[fruits[right]]++ == 0) {
                typeNum++;
            }
            while (typeNum > 2) {
                if (--types[fruits[left++]] == 0) {
                    typeNum--;
                }
            }
            maxLength = max(maxLength, right - left + 1);
        }
        return maxLength;
    }
};


int main() {
    auto map = unordered_map<int, int>();

    cout << map.count(3) << "," << map[3]++ << map[3] << endl;
}